package com.filter;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.servlet.M;
import com.servlet.My;

import hyl.ext.base.MySession;
import hyl.ext.base.Response;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyInterceptor2 implements HandlerInterceptor {
	//private final static Logger logger = LoggerFactory.getLogger(MyInterceptor2.class);
	@Override
	public boolean preHandle(HttpServletRequest req, HttpServletResponse res, Object handler) throws Exception {
		System.out.println("拦截3");
		MySession tk =My.getSession(req);
		// 过滤非法ip
		if (tk.getUserId()==null) {
			tk.msg.setCode(0, "请先登录");
			Response.forwardOrJson(req, res, M.URL_login,tk.msg);		
			return false;
		}		 

		return true;
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		
		//Token tk =(Token) 	request.getAttribute(Response.ATTR_TOKEN);
		//tk.state_wok[0]=Token.STATE0_已处理;
	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {

	}

}
